package com.platform.service.impl;

import com.github.pagehelper.PageInfo;
import com.platform.annotation.SysLog;
import com.platform.base.BaseService;
import com.platform.common.Const;
import com.platform.common.ServerResponse;
import com.platform.pojo.Meprice;
import com.platform.service.IMepriceService;
import com.platform.util.MapperUtil;
import com.platform.util.NumberUtil;
import com.platform.util.StringUtil;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@Service("iMepriceService")
public class MepriceServiceImpl extends BaseService implements IMepriceService {

    /**
     * 条件查询设备价格
     * @param paramMap
     * @param request
     * @return
     */
    @SysLog("条件查询设备价格")
    public ServerResponse<PageInfo> selectByParamMap(Map paramMap, HttpServletRequest request){
        paramMap.put("price",NumberUtil.safeToNumber(paramMap.get("price")));
        return MapperUtil.pageInfo(paramMap,mepriceMapper);
    }

    /**
     * ID查询设备价格详情
     * @param id
     * @param request
     * @return
     */
    @SysLog("ID查询设备价格详情")
    public ServerResponse<Map> selectById(Integer id,HttpServletRequest request){
        Map resultMap = mepriceMapper.selectById(id);
        if(null != resultMap){
            return ServerResponse.createBySuccess(Const.Msg.SELECTSUCCESS,resultMap);
        }
        return ServerResponse.createByErrorMessage(Const.Msg.SELECTERROR);
    }

    /**
     * 修改设备价格信息
     * @param paramMap
     * @param request
     * @return
     */
    @SysLog("修改设备价格信息")
    public ServerResponse<String> updateMeprice(Map paramMap,HttpServletRequest request){
        int id = NumberUtil.safeToNumber(paramMap.get("id"));
        if(id <= 0){
            return ServerResponse.createByErrorMessage(Const.Msg.PARAMTERERROR);
        }
        Meprice meprice = new Meprice();
        meprice.setId(id);
        meprice.setEname(StringUtil.valueOfString(paramMap.get("ename")));//设备名称
        meprice.setZbprice(StringUtil.valueOfString(paramMap.get("zbprice")));//中标单价
        meprice.setBrand(StringUtil.valueOfString(paramMap.get("brand")));//品牌
        meprice.setModel(StringUtil.valueOfString(paramMap.get("model")));//型号
        meprice.setNumbers(StringUtil.valueOfString(paramMap.get("numbers")));//数量、
        meprice.setSupplier(StringUtil.valueOfString(paramMap.get("supplier")));//供应商
        meprice.setManufacturer(StringUtil.valueOfString(paramMap.get("manufacturer")));//制造商
        meprice.setEtype(StringUtil.valueOfString(paramMap.get("etype")));//设备类型
        meprice.setContractprice(StringUtil.valueOfString(paramMap.get("contractprice")));//合同价格
        meprice.setZbmoney(StringUtil.valueOfString(paramMap.get("zbmoney")));//中标价格
        meprice.setBidtime(StringUtil.valueOfString(paramMap.get("bidtime")));//中标时间
        meprice.setTarea(StringUtil.valueOfString(paramMap.get("tarea")));//招标地区
        meprice.setAgency(StringUtil.valueOfString(paramMap.get("agency")));//代理机构
        meprice.setBiddingmethod(StringUtil.valueOfString(paramMap.get("biddingmethod")));//招标方式
        meprice.setEuunit(StringUtil.valueOfString(paramMap.get("euunit")));//设备使用单位
        meprice.setTitlename(StringUtil.valueOfString(paramMap.get("titlename")));//中标公告名称
        if(mepriceMapper.updateByPrimaryKeySelective(meprice) > 0){
            return ServerResponse.createBySuccessMessage(Const.Msg.UPDATESUCCESS);
        }
        return ServerResponse.createByErrorMessage(Const.Msg.UPDATEERROR);
    }

}
